package org.xsk.mall.pms.domain.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xsk.mall.common.page.PageUtils;
import org.xsk.mall.pms.dao.entity.PmsProductCategoryDO;
import org.xsk.mall.pms.dao.manager.PmsProductCategoryDaoManager;
import org.xsk.mall.pms.domain.convert.PmsProductCategoryDOConvert;
import org.xsk.mall.pms.domain.model.PmsProductCategoryModel;
import org.xsk.mall.pms.domain.model.PmsProductCategoryQueryModel;
import org.xsk.mall.pms.domain.service.PmsProductCategoryService;

import java.util.List;

@Service
public class PmsProductCategoryServiceImpl implements PmsProductCategoryService {

    @Autowired
    private PmsProductCategoryDaoManager productCategory;

    @Override
    public Page<PmsProductCategoryModel> pageQueryCategory(PmsProductCategoryQueryModel model) {
        Page<PmsProductCategoryDO> doPage = PageUtils.toPage(model.getPagination());
        Page<PmsProductCategoryModel> modelPage = PageUtils.toPage(model.getPagination());

        LambdaQueryWrapper<PmsProductCategoryDO> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByAsc(PmsProductCategoryDO::getId);
        Page<PmsProductCategoryDO> page = productCategory.page(doPage, wrapper);
        List<PmsProductCategoryModel> modelList = PmsProductCategoryDOConvert.INSTANCE.doListToModelList(page.getRecords());

        modelPage.setRecords(modelList).setTotal(doPage.getTotal());
        return modelPage;
    }
}